/*******************************************************
> Copyright (C) 2024 ==iot== All rights reserved.
> File Name: 2.c
> Author: wyf
> Created Time: 2024年09月02日 星期一 14时51分21秒
***************************************************/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LENGTH 32  
int decimalism_to_bin(int number, int* arr);


//将一个整型数字的第n个(二进制)位清0 
int clear_bit(int num, int n) {
    return num & ~(1 << n);
}


int main(int argc, const char* argv[])
{
    printf("请输入一个数：\n");
    int num;
    int res = 0;
    int arr[MAX_LENGTH] = { 0 };
    scanf("%d", &num);
    printf("输入的数，二进制是：\n");
    res = decimalism_to_bin(num, arr);

    for (int i = res - 1; i >= 0; i--)
    {
        printf("%d", arr[i]);
    }
    printf("\n");
    printf("请输入要清零的位数：\n");
    int n;
    scanf("%d", &n);
    res = 0;
    res = clear_bit(num, n);
    decimalism_to_bin(res, arr);

    printf("清零后，二进制是：\n");
    for (int i = res - 1; i >= 0; i--)
    {
        printf("%d", arr[i]);
    }

    return 0;

}


int decimalism_to_bin(int number, int* arr)
{
    int i = 0;

    while (number > 0)
    {
        arr[i] = number % 2;
        number /= 2;
        i++;
    }

    return i;
}